    package nemeanshop;

/**
 *
 * @author Ragnar
 */
public class Product 
{
    private int inStore;
    private int total;
    private double stockPrice;
    private double sellPrice;
    private String barcode;
    private String productName;
    private int quantity;
    
    public Product(String barcode, String productName, double stockPrice, double sellPrice, int qty)
    {
        this.barcode = barcode;
        this.productName = productName;
        this.stockPrice = stockPrice;
        this.sellPrice = sellPrice;
        this.quantity = qty;
    }
    
    public Product(String barcode, String productName, double sellPrice, int qty)
    {
        this.barcode = barcode;
        this.productName = productName;
        this.sellPrice = sellPrice;
        this.total = 1;
        this.quantity = --qty;
    }

    public int getInStore() 
    {
        return this.inStore;
    }
    
    public String getBarcode()
    {
        return this.barcode;
    }

    public String getProductName() {
        return this.productName;
    }

    public double getSellPrice() {
        return this.sellPrice;
    }

    public double getStockPrice() {
        return this.stockPrice;
    }

    public int getTotal() {
        return this.total;
    }
    
    public int getQty(){
        
        return this.quantity;
        
    }
    
    public String toString(){
        return "Produkt:" +this.productName;
    }
    
    /**
     * Increases the stores quantity of this product
     * ---------------------------------------------
     * @param quantity
     * @return 
     */
    public int incrementQuantity(int quantity) throws NemeanShopException
    {
       if ( (this.total - this.quantity) > 0 )
        {
            throw new NemeanShopException("Not enough products in store");
        }
        else
        {
            this.total += quantity;   
            return this.total;
        }
    }
    
    /**
     * Decrease the stores quantity of this product by x
     * --------------------------------------------
     * @param quantity
     * @return
     * @throws NemeanShopException 
     */
    public int decreaseQuantity(int quantity) throws NemeanShopException
    {
        if ( (this.total - quantity) < 0 )
        {
           
            throw new NemeanShopException("Not enough products in store");
        }
        else
        {
            this.total -= quantity;   
            return this.total;
        }
    }
    
    /**
     * Decrease the stores quantity of this product by one
     * --------------------------------------------
     * @param quantity
     * @return
     * @throws NemeanShopException 
     */
    public int decreaseQuantity() throws NemeanShopException
    {
        if ( this.total > 0 )
        {
            --this.total;
            return this.total;
        }
        else
        {
            throw new NemeanShopException("Not enough products in store");
        }
    }
}
